package com.ftg.learn.controller;

import com.ftg.learn.dto.AddProductDto;
import com.ftg.learn.service.ShopProductService;
import com.ftg.learn.util.PageEx;
import com.ftg.learn.util.R;
import com.ftg.learn.vo.ProductListVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 布衣
 */
@RestController
public class ShopProductController {

    @Resource
    private ShopProductService shopProductService;

    @GetMapping("/listForAll")
    public R<PageEx<ProductListVo>> listForAll(
            @RequestParam(value="categoryName", required = false) String categoryName,
            @RequestParam(value="productName", required = false) String productName,
            @RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize
    ) {
        return shopProductService.listForAll( categoryName,  productName, pageNum, pageSize);
    }

    @PostMapping("/saveProduct")
    public R<Integer> saveProduct(@RequestBody AddProductDto dto){
        return shopProductService.saveProduct(dto);
    }

}
